var api = require('../../api.js');
// var WxParse = require('../../wxParse/wxParse.js');
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {

        member: [{
                "id": "0",
                "img": "/images/five.png",
                "name": "成为会员享特权",
                "bind": "tozhuce"
            },
            {
                "id": "1",
                "img": "/images/yaoqing.png",
                "name": "邀请好友得奖励",
                "bind": "tofenxiang"
            },
        ],

    },
    // 跳分享
    tofenxiang: function() {
        wx.navigateTo({
            url: '/page/casa/pages/ashare/ashare',
        })
    },

    // 跳转注册
    tozhuce: function() {
        wx.navigateTo({
            url: '/page/casa/pages/sign_in/sign_in',
        })
    },
    // 跳转新人专享
    toexclusive: function(t) {
        var _id = t.currentTarget.dataset.packsid;
        console.log(t)
        wx.navigateTo({
            url: '/page/casa/pages/exclusive/exclusive?packs_id=' + _id,
        })
    },
    //这里是弹出框的js
    moad_click: function() {
        let that = this;
        that.setData({
            moad_mask: !that.data.moad_mask
        })
    },
    // 
    to_dial: function() {
        var t = this.data.store.contact_tel;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let that = this;

        let t = app.request;



        t({
            url: api.default.index,
            success: function(res) {
                console.log(res)

                console.log("=============================")
                // 缓存电话
                wx.setStorage({
                    key: 'phoneNum',
                    data: {
                        num: res.data.store
                    },
                })
                that.setData({
                    store: res.data.store,
                    banner: res.data.banner_list,
                    user_price: res.data.packs
                })
                // t({
                //     url: api.default.navbar,
                //     success: function(res) {
                //         that.setData({
                //             _navbar: res.data
                //         })
                //     },
                // })
            },

        })
        //判断是否已领取大礼包
        // that.setData({
        //     is_packs: user.user_info.is_packs,
        //     packs_id: user.user_info.packs.id,
        // });
        // if (that.data.is_packs == 0 && that.data.packs_id) {
        //     that.setData({
        //         moad_mask: false, //未领取
        //     })
        // } else {
        //     that.setData({
        //         moad_mask: true, //已领取
        //     })
        // }
        // console.log(this.data.moad_mask, 111111111);
        let user = wx.getStorageSync("pages_user_user");
        // 礼包领取状态
        let _type = wx.getStorageSync("pages_user_user").user_info.is_packs;
        if (_type == 1) { //已领取 隐藏
            that.setData({
                moad_mask: true
            })
        }
        console.log(user);


    },

    loadData: function(t) {
        var s = this,
            a = wx.getStorageSync("pages_index_index");
        a && (a.act_modal_list = [], s.setData(a)), app.request({
            url: api.default.index,
            success: function(t) {
                console.log(t);
                if (0 == t.code) {
                    page_first_init ? page_first_init = !1 : t.data.act_modal_list = [];
                    var a = t.data.topic_list,
                        e = new Array();
                    if (a && 1 != t.data.update_list.topic.count) {
                        if (1 == a.length) e[0] = new Array(), e[0] = a;
                        else
                            for (var i = 0, n = 0; i < a.length; i += 2,
                                n++) null != a[i + 1] && (e[n] = new Array(), e[n][0] = a[i], e[n][1] = a[i + 1]);
                        t.data.topic_list = e;
                    }
                    s.setData(t.data), wx.setStorageSync("store", t.data.store), wx.setStorageSync("pages_index_index", t.data);
                    var o = wx.getStorageSync("user_info");
                    o && s.setData({
                        _user_info: o
                    }), s.miaoshaTimer();
                }
            },
            complete: function() {
                wx.stopPullDownRefresh();
            }
        });
    },



    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {


    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

        var that = this;


        var menu = wx.getStorageSync("casa_navbar");

        console.log(menu)                  
        console.log("menu======================================")          
        menu.navs[0].active = true;
        menu.navs[2].active = false;        
        that.setData({
            _navbar: menu
        })

        // wx.getStorage({
        //     key: 'casa_navbar',
        //     success: function(res) {
        //         console.log(res.data)
        //         that.setData({
        //             _navbar: res.data.nav_
        //         })
        //     }
        // })



    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})